<template>
	<div>
		<van-nav-bar
			title="创建新班课"
			left-arrow
			left-text="返回"
			fixed
			@click-left="$router.go(-1)"
		/>
		<!-- <van-uploader v-model="headImage" :after-read="afterRead" accept="image/png, image/jpeg" :max-count="1"/> -->
		
		<van-form @submit="onCreateBanke">
			<bankeInfo ref="bankeInfo" ></bankeInfo>

			<div style="margin: 16px;">
				<van-button round block type="info" native-type="submit">{{btnMsg}}</van-button>
			</div>
		</van-form>
		
	</div>
</template>

<script>
	// import { pageCourse } from '../../api/course.js';
	import bankeInfo from '../../components/bankeInfo.vue';
	import { saveCourse } from '../../api/course.js';
	import { Toast } from 'vant';
	export default {
		components: {
			bankeInfo
		},
		created() {
			
		},
		data() {
			return {
				// headImage: [],
				
			}
		},
		computed: {
			btnMsg() {
				return '创建';
			}
		},
		methods: {
			
			onCreateBanke() {  // 教师创建一个班课
				const info = {
					title: this.$refs.bankeInfo.title, // 班级名称*
					courseName: this.$refs.bankeInfo.courseName, // 课程名称*
					teacher: this.$refs.bankeInfo.teacher,  // 任课教师
					college: this.$refs.bankeInfo.college, // 学校*
					school: this.$refs.bankeInfo.school, // 学院*
					major: this.$refs.bankeInfo.major, // 专业
					grade: Number(this.$refs.bankeInfo.grade), // 年级*
					semester: this.$refs.bankeInfo.semester, // 学期*
					learnRequire: this.$refs.bankeInfo.learnRequire, // 学习要求
					teachProgress: this.$refs.bankeInfo.teachProgress, // 教学进度
					collegeId: this.$refs.bankeInfo.colCollegeId[this.$refs.bankeInfo.collegeIndex]
				};
				const entity = { 
					"organId": info.collegeId,
					"grade": info.grade,
					"name": info.courseName,
					"semester": info.semester,
					"title": info.title
				};				
				saveCourse(entity).then(res => {
					console.log(res);
					if(res.data.code === 0) {
						// 创建成功
						Toast('创建成功');
						// localStorage.setItem('detailBankeInfo' , JSON.stringify(this.$route.params.detailBankeInfo));
						setTimeout(() => {
							this.$router.push({
								name: 'newBankeSuccess',
								params: {
									newBankeSuccess: res.data.data
								}
							});
						},100);
					}
					else {
						// 创建失败
						Toast(res.data.msg);
						this.$router.push({name: "home"});
					}
				}).catch(err => {
					console.log(err);
					Toast('请求失败或超时');
				})
			},
			afterRead(file) {
				// 此时可以自行将文件上传至服务器
				
				console.log(file);
			},
		}
	}
</script>

<style>
</style>
